package com.ruoyi.pay.service;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.alipay.api.AlipayClient;
@Service
public class AliPayService {

    @Autowired
    AlipayClient alipayClient;

    public String alipay_trade_page_pay(String out_trade_no,Double total_amount,String subject,String body) throws AlipayApiException {
        //获得初始化的AlipayClient
        //设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();

        Map map = new HashMap<>();
        map.put("out_trade_no",out_trade_no);
        map.put("total_amount",total_amount);
        map.put("subject",subject);
        map.put("body",body);
        map.put("product_code","FAST_INSTANT_TRADE_PAY");
        String jsonString = JSON.toJSONString(map);
        alipayRequest.setBizContent(jsonString);
        String result = alipayClient.pageExecute(alipayRequest).getBody();

        System.out.println(result);

        return result;

    }
}
